<?php

namespace app\admin\service;


use app\admin\controller\Order;
use app\admin\model\AuthGroupAccess;
use app\admin\validate\Admin;
use think\exception\ValidateException;
use app\traits\Result;
use app\admin\model\Admin as AdminModel;
use think\facade\Config;
use think\helper\Str;
use think\crypt\Crypt;
use app\common\model\Store;

class CommonService
{
    use Result;
    public  static  function my_dir($dir) {
        $files = array();
        if(@$handle = opendir($dir)) {
            while(($file = readdir($handle)) !== false) {
                if($file != ".." && $file != ".") {

                    if(is_dir($dir."/".$file)) { //递归字文件夹
                        $files[$file] = self::my_dir($dir."/".$file);
                    } else { //不然就将文件的名字存入数组；
                        $files[] = $file;
                    }

                }
            }
            closedir($handle);
            $data =[];
            $i = 0;
            foreach($files as $k => $v) {
                $i++;//双重循环内，i每次加1
                $data[$i]['id'] =$i;

                if(is_array($v)){
                    $j = 0;//给一个变量，每次循环它就定义成0，到达下标都从0开始
                    if (is_array($v)) {
                        foreach ($v as $vs) {
                            $data[$k][$i]['child'] = $vs;
                            $j++;//双重循环内，i每次加1
                        }
                    }
                }else{
                    $data[$i]['name'] =$v;
                }

            }
//            dump($files);die;
//            $files =   self::getTreeOrder($files);
            return $data;

        }
    }

    /**
     * 递归  列
     * @param $array
     * @param $id
     * @return array
     */
    public static function getTreeOrder($array,$id = 0,$level = 0){
        static $arr = [];
        foreach($array as $k=>$v){
            // if($v['parent_id'] == $id){
//            $v['level'] = $level;
//            $str ="";
//            for ($i=0;$i<$level;$i++){
//                $str = $str."|----";
//            }
        //    $v['levelName'] = $str.''.$v['name'];
            $arr[] = $v;
            unset($array[$k]);
            self::getTreeOrder($array,$v,$level+1);
        }
        //   }
        return $arr;
    }

}